#ifndef __MOTOR_H
#define __MOTOR_H

#include "PID.h"

#define MOTOR_OFF           0
#define MOTOR_ON            1

#define ENCODER_TIM         &htim2
#define ENCODER_CHA         TIM_CHANNEL_1
#define ENCODER_CHB         TIM_CHANNEL_2
#define PWM_TIM             &htim3
#define PWM_CH              TIM_CHANNEL_1

typedef struct
{
    uint8_t duty;
    int16_t overflow_num;
    uint16_t count[2];//此次和上次的转动计数
    float position[2];//此次和上次的角位置，考虑了溢出，单位为r
    float speed;//单位为rpm

    PID_t pid_speed;
    PID_t pid_position;

}MOTOR_t;

void motor_init(MOTOR_t *motor);
void motor_config(uint8_t motor_state);
void motor_set_position(MOTOR_t *motor,float r);
void motor_work(MOTOR_t *motor);

#endif
